package com.weisy.signin.ui.activity;

import android.os.Handler;

import com.alibaba.android.arouter.launcher.ARouter;
import com.weisy.signin.R;
import com.weisy.signin.base.BaseAcativity;
import com.weisy.signin.comm.Comm;
import com.weisy.signin.utils.SpUtils;

/**
 * @author weisy
 * @function
 * @date 2019/3/20 23:13
 */
public class SplashActivity extends BaseAcativity {
    @Override
    public void findView() {
        setContentView(R.layout.activity_splash);
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            new Handler().postDelayed(() -> {
                if (SpUtils.contains(context, Comm.SP_LOGIN)) {
                    boolean isLogin = (boolean) SpUtils.get(context, Comm.SP_LOGIN, false);
                    int userType = (int) SpUtils.get(context, Comm.SP_TYPE, 1);
                    if (isLogin) {
                        ARouter.getInstance().build(userType == 1 ? Comm.ROUTE_STUDENT : Comm.ROUTE_TEACHER).navigation();
                        finish();
                        return;
                    }
                }
                ARouter.getInstance().build(Comm.ROUTE_LOGIN).navigation();
                finish();
            }, 2000);
        }
    }
}
